//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.persistence;

import org.jpgolay.me.customer.Customer;
import org.jpgolay.me.family.Family;
import org.jpgolay.me.item.Item;
import org.jpgolay.me.supplier.Supplier;
import org.jpgolay.me.user.User;

// Referenced classes of package org.jpgolay.me.persistence:
//            ObjectCRUD
public class IfExist {

    public IfExist() {
        crud = new ObjectCRUD();
    }

    public boolean customerId(String customerId) {
        return selectCustomer(customerId);
    }

    public boolean supplierId(String supplierId) {
        return selectSupplier(supplierId);
    }

    public boolean itemId(String itemId) {
        return selectItem(itemId);
    }

    public boolean itemFamilyId(String id) {
        return selectItemFamily(id);
    }

    public boolean customerFamilyId(String id) {
        return selectCustomerFamily(id);
    }

    public boolean supplierFamilyId(String id) {
        return selectSupplierFamily(id);
    }

    public boolean salesPersonFamilyId(String id) {
        return selectSalesPersonFamily(id);
    }

    public boolean userId(String id) {
        return selectUser(id);
    }

    private boolean selectCustomer(String pk) {
        Customer customer = (Customer) crud.read(pk, 27);
        return customer != null;
    }

    private boolean selectSupplier(String pk) {
        Supplier supplier = (Supplier) crud.read(pk, 9);
        return supplier != null;
    }

    private boolean selectItem(String pk) {
        Item item = (Item) crud.read(pk, 11);
        return item != null;
    }

    private boolean selectItemFamily(String pk) {
        Family family = (Family) crud.read(pk, 12);
        return family != null;
    }

    private boolean selectCustomerFamily(String pk) {
        Family family = (Family) crud.read(pk, 46);
        return family != null;
    }

    private boolean selectSupplierFamily(String pk) {
        Family family = (Family) crud.read(pk, 10);
        return family != null;
    }

    private boolean selectSalesPersonFamily(String pk) {
        Family family = (Family) crud.read(pk, 39);
        return family != null;
    }

    private boolean selectUser(String pk) {
        User user = (User) crud.read(pk, 19);
        return user != null;
    }
    private ObjectCRUD crud;
}
